package com.hulei.memcached.spymemcached;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.spy.memcached.MemcachedClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.net.InetSocketAddress;

@Configuration
@Slf4j
public class SpyMemcachedConfig implements CommandLineRunner {

        @Value("${SpyMemcached.memcached.ip}")
        private String ip;
        @Value("${SpyMemcached.memcached.port}")
        private int port;

        @Getter
        private MemcachedClient client = null;

	@Override
	public void run(String... args) {
		try {
			client = new MemcachedClient(new InetSocketAddress(ip,port));
		} catch (IOException e) {
			log.error("SpyMemcached初始化失败",e);
			throw new RuntimeException("SpyMemcached初始化失败");
		}
	}

}
